package com.sj.configuration.jfinal;


import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
import com.jfinal.template.source.ClassPathSourceFactory;
import com.sj.model._MappingKit;

@Configuration
public class JfinalConfiguration {
	@Autowired
	private DataSource datasource;
	
	@Bean
	public ActiveRecordPlugin activeRecordPlugin(){
		ActiveRecordPlugin activeRecordPlugin = new ActiveRecordPlugin(this.datasource);
		activeRecordPlugin.setShowSql(true);
		activeRecordPlugin.setDialect(new MysqlDialect());
		activeRecordPlugin.getEngine().setSourceFactory(new ClassPathSourceFactory());
		activeRecordPlugin.addSqlTemplate("templates/sql/all_sqls.sql");
		_MappingKit.mapping(activeRecordPlugin);
		activeRecordPlugin.start();
		return activeRecordPlugin;
	}
	
}
